import { http } from "@/utils/http";

export type UserResult = {
  token: string,
  user: {
    username: string,
    mobile: string,
    type: number,
    token: string
  }
}

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};
export const loginApi = "/usercenter/login.account"
/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", loginApi, { data });
};
export const refreshTokenURL = "/refresh-token"
/** 刷新`token` */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>("post", refreshTokenURL, { data });
};

/**
 * 给出用户信息
 * @returns 
 */
export const getUserInfo = () => {
  return http.request("get", "/user/getUserInfo");
};

export const loginByVerifyCodeURL = "/usercenter/login.mobileLogin"
/**
 * 通过验证码登陆
 * @returns 
 */
export const loginByVerifyCode = (data: { mobile: string, code: string }) => {
  return http.post<UserResult>(loginByVerifyCodeURL, { data })
}